let baseURL = "http://api-breakingnews-web.itheima.net"

$.ajaxPrefilter(function (options) {
    options.url = baseURL + options.url;

    // 2.身份验证
    if (options.url.indexOf("/my/" != -1)) {
        options.headers = {
            Authorization: localStorage.getItem('token') || ""
        }

    }
    // 3.拦截所有相应
    options.complete = function (res) {
        // console.log(res.responseJSON)
        let obj = res.responseJSON;

        if (obj.status == 1 && obj.message == "身份认证失败！") {
            // 1.清空本地token
            localStorage.removeItem('token')
            // 2.页面跳转
            location.href = "/login.html";
        }
    }
});